# Maintainer: Leonidas Spyropoulos <artafinde@archlinux.org>

pkgname=gitlab-exporter
pkgver=0.5.1
pkgrel=1
pkgdesc='A Gitlab prometheus metric exporter'
arch=('loong64' 'x86_64')
url='https://gitlab.archlinux.org/artafinde/gitlab-exporter'
license=('MIT')
depends=('gcc-libs' 'openssl')
makedepends=('cargo')
source=("https://gitlab.archlinux.org/archlinux/${pkgname}/-/releases/v${pkgver}/downloads/${pkgname}-${pkgver}.tar".gz{,.sig})
sha256sums=('396089aa3cd0892a56dd24572cbd0b6f4a5ce14354593828d0f0ea48bcd08a55'
            'SKIP')
b2sums=('4b7f0461192b1c90dbf89a43c0e19d475a37be1b4fc5351896673dcbdd2f82a55fed1a080ef71b4c56dfc1196ce9d52a861a14bbe62ff2591d3483f3a737f170'
        'SKIP')
validpgpkeys=(
  'B4B759625D4633430B74877059E43E106B247368' # Leonidas Spyropoulos <artafinde@archlinux.org>
) 

prepare() {
  cd "${pkgname}-${pkgver}"
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "${pkgname}-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  CFLAGS+=' -ffat-lto-objects'
  cargo build --release --frozen
}

check() {
  cd "${pkgname}-${pkgver}"
  export RUSTUP_TOOLCHAIN=stable
  CFLAGS+=' -ffat-lto-objects'
  cargo test --frozen -- --test-threads 1
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dm755 target/release/${pkgname} -t "${pkgdir}"/usr/bin
  install -Dm644 README.md -t "${pkgdir}"/usr/share/doc/${pkgname}
  install -Dm644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
